﻿namespace Ross.BSCSystem.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Http;
    using System.Threading.Tasks;
    using System.Web.Http;
    using System.Web.Http.Results;
    using Newtonsoft.Json;
    using Ross.EntityFramework;
    using Ross.Service;

    //[SimpleAuthenticationFilter]
    public class ValuesController : BaseApiController
    {
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public void Post([FromBody]string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }

        public async Task<JsonResult<ResultDto<List<Service.Dto.BudgetFee>>>> GetFeesAsync(string ExpenseIndex, string DepartmentID)
        {
            ResultDto<List<Service.Dto.BudgetFee>> result = new ResultDto<List<Service.Dto.BudgetFee>>();
            BaseService srv = new BaseService();
            string url = this.BudgetServer + "/api/Budget/GetPrice?ExpenseIndex=" + ExpenseIndex + "&DepartmentID=" + DepartmentID;
            string response = await srv.RemoteGet(url);
            result = JsonConvert.DeserializeObject<ResultDto<List<Service.Dto.BudgetFee>>>(response);
            return this.Json(result);
        }

        public async Task<JsonResult<ResultDto<List<Service.Dto.ExpenseCate>>>> GetCateAsync()
        {
            ResultDto<List<Service.Dto.ExpenseCate>> result = new ResultDto<List<Service.Dto.ExpenseCate>>();
            //BaseService srv = new BaseService();
            //string url = this.BudgetServer + "/api/Expense/GetAllList";
            //string response = await srv.RemoteGet(url);
            //result = JsonConvert.DeserializeObject<ResultDto<List<Service.Dto.ExpenseCate>>>(response);
            List<Service.Dto.ExpenseCate> expCate = new List<Service.Dto.ExpenseCate>();
            expCate.Add(new Service.Dto.ExpenseCate { ExpenseIndex = "FeeXZ", ExpenseName = "行政费" });
            expCate.Add(new Service.Dto.ExpenseCate { ExpenseIndex = "FeeCL", ExpenseName = "差旅费" });
            result.datas = expCate;
            return this.Json(result);
        }

        public async Task<JsonResult<ResultDto<List<Service.Dto.Depart>>>> GetDeptAsync()
        {
            ResultDto<List<Service.Dto.Depart>> result = new ResultDto<List<Service.Dto.Depart>>();
            List<Service.Dto.Depart> departs = new List<Service.Dto.Depart>();
            departs.Add(new Service.Dto.Depart { DepartmentID = "IT", DepartmentName = "IT部" });
            departs.Add(new Service.Dto.Depart { DepartmentID = "HR", DepartmentName = "人事部" });
            departs.Add(new Service.Dto.Depart { DepartmentID = "PD", DepartmentName = "采购部" });
            departs.Add(new Service.Dto.Depart { DepartmentID = "MD", DepartmentName = "生产部" });
            result.datas = departs;
            //BaseService srv = new BaseService();
            //string url = this.BudgetServer + "/api/Department/GetAllList?userId=000022";
            //string response = await srv.RemoteGet(url);
            //result = JsonConvert.DeserializeObject<ResultDto<List<Service.Dto.Depart>>>(response);
            return this.Json(result);
        }
    }
}
